package com.zyf.chapter02.behavior.memento.v2;

/**
 * 输入的文本
 * <p>重构点：
 *  1.暴露不应该暴露的函数，setText() 函数很有可能被其他业务使用
 * @author yifeng
 */
public class InputText {
    private StringBuilder text = new StringBuilder();

    public String getText() {
        return text.toString();
    }

    public void append(String input) {
        text.append(input);
    }

    public Snapshot createSnapshot() {
        return new Snapshot(text.toString());
    }

    public void restoreSnapshot(Snapshot snapshot) {
        this.text.replace(0, this.text.length(), text.toString());
    }

    @Override
    public String toString() {
        return text.toString();
    }
}